﻿using System.Configuration;
using System.IO;
using System.Threading;

namespace SimpleDataAccessConsole
{
    internal class Program
    {
        private const string ConnectionStringName = "ConnectionString";

        private static void Main()
        {
            var connectionString = ConfigurationManager.ConnectionStrings[ConnectionStringName].ConnectionString;
            var providerName = ConfigurationManager.ConnectionStrings[ConnectionStringName].ProviderName;
            var data = new AppDatabase(providerName, connectionString);


            var simpleQuery = new Report001
                                  {
                                      Parameters = new object[] {Thread.CurrentPrincipal.Identity.Name}
                                  };

            var results = data.ExecuteReport(simpleQuery);

            // Write each row to a file.
            using (var streamWriter = new StreamWriter("result.csv"))
            {
                foreach (var row in results)
                {
                    streamWriter.Write(row);
                }
            }
        }
    }
}